<template>
  <div id="app">
    <!-- <nav>
      <router-link to="/">Home</router-link> |
      <router-link to="/about">About</router-link>
    </nav> -->
    <transition :name="transitionName">
      <router-view class="router-view" />
    </transition>
  </div>
</template>
<script>
export default {
  data() {
    return {
      transitionName: "",
    };
  },
  mounted() {
    if (this._isMobile()) {
      localStorage.setItem('device','mobile')
    } else {
      localStorage.setItem('device','pc')
    }
  },
  methods: {
    _isMobile() {
      let flag = navigator.userAgent.match(
        /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
      );
      return flag;
    },
  },
  watch: {
    $route(to, form) {
      console.log(to, "to=====");
      console.log(form, "form=====");
      if (form.meta.index === -999) {
        this.transitionName = "fade";
        return;
      } else if (to.meta.index < form.meta.index) {
        this.transitionName = "slide-right";
      } else if (to.meta.index > form.meta.index) {
        this.transitionName = "slide-left";
      } else {
        this.transitionName = "";
      }
    },
  },
};
</script>

<style lang="scss">
@import "./common/common.css";
body {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.router-view {
  position: absolute;
}

.slide-left-enter-active,
.slide-left-leave-active,
.slide-right-enter-active,
.slide-right-leave-active {
  transition: transform 1s !important;
  position: absolute;
}

.fade-enter,
.fade-leave-to {
  opacity: 0;
}
.fade-enter-to,
.fade-leave {
  opacity: 1;
}
.fade-enter-active,
.fade-leave-active {
  transition: opacity 2s ease !important;
  position: absolute;
}

.slide-right-enter {
  transform: translateX(-100%);
}
.slide-right-leave-active {
  transform: translateX(100%);
}

// .slide-right-leave-from {
//   transform: translateX(0);
// }
// .slide-right-leave-to {
//   transform: translateX(-100%);
// }

.slide-left-enter {
  transform: translateX(100%);
}
.slide-left-leave-active {
  transform: translateX(-100%);
}

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  // text-align: center;
  color: #2e0c00;
}
body {
  padding: 0;
  margin: 0;
}
nav {
  // padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>
